package com.yun.algorithmproblem.leetcode;

import com.yun.datastructure.linear.list.linkedlist.ListNode;

public class Leetcode2 {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode sentinel = new ListNode();
        ListNode p=sentinel;
        int cin = 0;
        while (l1 != null || l2 != null||cin!=0) {
            if(l1!=null){
                cin+=l1.val;
                l1=l1.next;
            }
            if(l2!=null){
                cin+=l2.val;
                l2=l2.next;
            }
            p.next=new ListNode(cin%10);
            p=p.next;
            cin/=10;
        }
        return sentinel.next;
    }

}
